﻿namespace WMS6.Web.Billing
{
    using System;
    using System.Collections.Generic;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;

    public class BillingStorageQuery : BasePage
    {
        protected Button btnRun;
        protected DropDownList ddlMonth;
        protected DropDownList ddlYear;
        protected HtmlForm F9240;
        protected HtmlInputHidden hdnActionID;
        protected HtmlInputHidden hdncalendarFlag;
        protected HtmlInputHidden hdnDataFormat;
        protected HtmlHead Head1;
        protected HtmlImage img1;
        protected Label lblBillingStorage;
        protected Label lblMsg;
        protected Label lblOwnerID;
        protected Label lblStatementDate;
        protected HtmlLink mycss;
        protected ScriptManager ScriptManager1;
        protected TextBox txtOwnerID;

        protected void btnRun_Click(object sender, EventArgs e)
        {
            string starageDate = this.ddlYear.SelectedValue + "-" + this.ddlMonth.SelectedValue + "-01";
            string ownerID = this.txtOwnerID.Text.Trim();
            List<string> ownerIDS = new List<string>();
            if (!string.IsNullOrEmpty(ownerID))
            {
                ownerIDS.Add(ownerID);
            }
            try
            {
                string startTime = DateTime.Now.ToString();
                string result = BillingServiceClientProxy.GetInstance().GenerateStorageChargesBillingCredence(starageDate, ownerIDS);
                if (string.IsNullOrEmpty(result))
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F9220_003");
                }
                else
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F9220_004") + result;
                }
                this.Session["FailInfo"] = result;
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>$.unblockUI();</script>", false);
            }
            base.Server.Transfer("BillingStorageList.aspx?action=" + this.hdnActionID.Value, false);
        }

        private void LoadDDl()
        {
            this.ddlYear.SelectedValue = DateTime.Now.Year.ToString();
            string month = DateTime.Now.Month.ToString();
            if (month.Length == 1)
            {
                month = "0" + month;
            }
            this.ddlMonth.SelectedValue = month;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadDDl();
                this.hdnDataFormat.Value = "yyyy-MM-dd";
            }
        }

        public string Owner
        {
            get
            {
                return this.txtOwnerID.Text.Trim();
            }
        }

        public string OwnerID
        {
            get
            {
                if (!string.IsNullOrEmpty(this.txtOwnerID.Text.Trim()))
                {
                    return base.GetParamsString(this.txtOwnerID.Text.Trim(), "Same As");
                }
                return "";
            }
        }

        public string StorageDate
        {
            get
            {
                if (!string.IsNullOrEmpty(this.ddlYear.SelectedValue))
                {
                    return base.GetParamsString(this.ddlYear.SelectedValue + "-" + this.ddlMonth.SelectedValue + "-01", "Same As");
                }
                return "";
            }
        }
    }
}

